#pragma once
#include "ZuiLib.h"
#include "LRefObject.h"
#include "LUtils.h"

namespace ZuiLib {

class LContainer :public LRefObject<ZContainer>
{
public:

	int getItemAt(LuaFuncState& L)
	{
		return L.lreturn(LuaClass<ZControl>::cToLua(&L,pThis->GetItemAt(L.arg(0).toInt())));
	}

	int getItemByName(LuaFuncState& L)
	{
		return L.lreturn(LuaClass<ZControl>::cToLua(&L, pThis->GetItemByName(L.arg(0).toString())));
	}


	int getItemIndex(LuaFuncState& L)
	{
		ZControl* ctrl = LuaClass<ZControl>::luaToC(L.arg(0));
		return L.lreturn(pThis->GetItemIndex(ctrl));
	}

	int setItemIndex(LuaFuncState& L)
	{
		ZControl* ctrl = LuaClass<ZControl>::luaToC(L.arg(0));
		return L.lreturn(pThis->SetItemIndex(ctrl,L.arg(1).toInt()));
	}

	int getCount(LuaFuncState& L)
	{
		return L.lreturn(pThis->GetCount());
	}

	int add(LuaFuncState& L)
	{
		ZControl* ctrl = LuaClass<ZControl>::luaToC(L.arg(0));
		return L.lreturn(pThis->Add(ctrl));
	}

	int addAt(LuaFuncState& L)
	{
		ZControl* ctrl = LuaClass<ZControl>::luaToC(L.arg(0));
		return L.lreturn(pThis->AddAt(ctrl,L.arg(1).toInt()));
	}

	int remove(LuaFuncState& L)
	{
		ZControl* ctrl = LuaClass<ZControl>::luaToC(L.arg(0));
		return L.lreturn(pThis->Remove(ctrl));
	}

	int removeAt(LuaFuncState& L)
	{
		return L.lreturn(pThis->RemoveAt(L.arg(0).toInt()));
	}

	int removeLast(LuaFuncState& L)
	{
		pThis->RemoveLast();
		return 0;
	}

	int removeAll(LuaFuncState& L)
	{
		pThis->RemoveAll();
		return 0;
	}

	int getInset(LuaFuncState& L)
	{
		return L.lreturn(toLua(&L,pThis->GetInset()));
	}

	int setInset(LuaFuncState& L)
	{
		pThis->SetInset(toRect(L.arg(0)));
		return 0;
	}

	int getChildPadding(LuaFuncState& L)
	{
		return L.lreturn(pThis->GetChildPadding());
	}

	int setChildPadding(LuaFuncState& L)
	{
		pThis->SetChildPadding(L.arg(0).toInt());
		return 0;
	}

	int getChildAlign(LuaFuncState& L)
	{
		return L.lreturn(pThis->GetChildAlign());
	}

	int setChildAlign(LuaFuncState& L)
	{
		pThis->SetChildAlign(L.arg(0).toInt());
		return 0;
	}

	int getChildVAlign(LuaFuncState& L)
	{
		return L.lreturn(pThis->GetChildVAlign());
	}

	int setChildVAlign(LuaFuncState& L)
	{
		pThis->SetChildVAlign(L.arg(0).toInt());
		return 0;
	}

	int isDelayedDestroy(LuaFuncState& L)
	{
		return L.lreturn(pThis->IsDelayedDestroy());
	}

	int setDelayedDestroy(LuaFuncState& L)
	{
		pThis->SetDelayedDestroy(L.arg(0).toBool());
		return 0;
	}

	int isMouseChildEnabled(LuaFuncState& L)
	{
		return L.lreturn(pThis->IsMouseChildEnabled());
	}

	int setMouseChildEnabled(LuaFuncState& L)
	{
		pThis->SetMouseChildEnabled(L.arg(0).toBool());
		return 0;
	}

	int findSelectable(LuaFuncState& L)
	{
		return L.lreturn(pThis->FindSelectable(L.arg(0).toInt(),L.arg(1).toBool()));
	}

	int getScrollPos(LuaFuncState& L)
	{
		return L.lreturn(toLua(&L, pThis->GetScrollPos()));
	}

	int getScrollRange(LuaFuncState& L)
	{
		return L.lreturn(toLua(&L, pThis->GetScrollRange()));
	}

	int setScrollPos(LuaFuncState& L)
	{
		pThis->SetScrollPos(toSize(L.arg(0)));
		return 0;
	}

	int lineUp(LuaFuncState& L)
	{
		pThis->LineUp();
		return 0;
	}

	int lineDown(LuaFuncState& L)
	{
		pThis->LineDown();
		return 0;
	}

	int pageUp(LuaFuncState& L)
	{
		pThis->PageUp();
		return 0;
	}

	int pageDown(LuaFuncState& L)
	{
		pThis->PageDown();
		return 0;
	}

	int homeUp(LuaFuncState& L)
	{
		pThis->HomeUp();
		return 0;
	}

	int endDown(LuaFuncState& L)
	{
		pThis->EndDown();
		return 0;
	}

	int lineLeft(LuaFuncState& L)
	{
		pThis->LineLeft();
		return 0;
	}

	int lineRight(LuaFuncState& L)
	{
		pThis->LineRight();
		return 0;
	}

	int pageLeft(LuaFuncState& L)
	{
		pThis->PageLeft();
		return 0;
	}
	int pageRight(LuaFuncState& L)
	{
		pThis->PageRight();
		return 0;
	}
	int homeLeft(LuaFuncState& L)
	{
		pThis->HomeLeft();
		return 0;
	}
	int endRight(LuaFuncState& L)
	{
		pThis->EndRight();
		return 0;
	}

	int enableScrollBar(LuaFuncState& L)
	{
		pThis->EnableScrollBar(L.arg(0).toBool(), L.arg(1).toBool());
		return 0;
	}

	int findControl(LuaFuncState& L)
	{
		ZControl* pCtrl = pThis->GetManager()->FindSubControlByName(pThis, L.arg(0).toString());
		if (pCtrl)
			return L.lreturn(LuaClass<ZControl>::cToLua(&L, pCtrl));
		else
			return 0;
	}


	int isExpandChild(LuaFuncState& L)
	{
		return L.lreturn(pThis->IsExpandChild());
	}

	int setExpandChild(LuaFuncState& L)
	{
		pThis->SetExpandChild(L.arg(0).toBool());
		return 0;
	}

    int addFromXml(LuaFuncState& L)
    {
        return L.lreturn(pThis->AddFromXml(L.arg(0).toString()));
    }

	BEGIN_MAP_FUNC(LContainer)
	DECLARE_FUNC(getItemAt),
	DECLARE_FUNC(getItemByName),
	DECLARE_FUNC(getItemIndex),
	DECLARE_FUNC(setItemIndex),
	DECLARE_FUNC(getCount),
	DECLARE_FUNC(add),
	DECLARE_FUNC(addAt),
	DECLARE_FUNC(remove),
	DECLARE_FUNC(removeAt),
	DECLARE_FUNC(removeLast),
	DECLARE_FUNC(removeAll),
	DECLARE_FUNC(getInset),
	DECLARE_FUNC(setInset),
	DECLARE_FUNC(getChildPadding),
	DECLARE_FUNC(setChildPadding),
	DECLARE_FUNC(getChildAlign),
	DECLARE_FUNC(setChildAlign),
	DECLARE_FUNC(getChildVAlign),
	DECLARE_FUNC(setChildVAlign),
	DECLARE_FUNC(isDelayedDestroy),
	DECLARE_FUNC(setDelayedDestroy),
	DECLARE_FUNC(isMouseChildEnabled),
	DECLARE_FUNC(setMouseChildEnabled),
	DECLARE_FUNC(findSelectable),
	DECLARE_FUNC(getScrollPos),
	DECLARE_FUNC(getScrollRange),
	DECLARE_FUNC(setScrollPos),
	DECLARE_FUNC(lineUp),
	DECLARE_FUNC(lineDown),
	DECLARE_FUNC(pageUp),
	DECLARE_FUNC(pageDown),
	DECLARE_FUNC(homeUp),
	DECLARE_FUNC(endDown),
	DECLARE_FUNC(lineLeft),
	DECLARE_FUNC(lineRight),
	DECLARE_FUNC(pageLeft),
	DECLARE_FUNC(pageRight),
	DECLARE_FUNC(homeLeft),
	DECLARE_FUNC(endRight),
	DECLARE_FUNC(enableScrollBar),
	DECLARE_FUNC(findControl),
	DECLARE_FUNC(isExpandChild),
	DECLARE_FUNC(setExpandChild),
    DECLARE_FUNC(addFromXml),
	END_MAP_FUNC
};

}//namespace
